package com.ruoyi.getopenid.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.kevinsawicki.http.HttpRequest;
import com.ruoyi.getopenid.service.WeChatUserLoginService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class WeChatUserLoginimpl implements WeChatUserLoginService {

        @Override
        public String codetoopenid(String code) {
            Map<String, String> data = new HashMap<String, String>();
            data.put("appid", "wx79f3a07c0ccb456c");
            data.put("secret", "e97d891976eb1f5de6b5426fddbaca71");
            data.put("js_code", code);
            data.put("grant_type", "authorization_code");
            String response = HttpRequest.get("https://api.weixin.qq.com/sns/jscode2session").form(data).body();
            System.out.println("Response was: " + response);
            JSONObject obj= JSON.parseObject(response);//将json字符串转换为json对
            System.out.println(obj);
            return response;
        }

}
